import argparse
import re

import command
import config
import utils


def git_log():
    parser = argparse.ArgumentParser(description='GIT 提交日志查询')
    parser.add_argument('-a', '--author', nargs='?', default='', help='作者')
    parser.add_argument('--after', nargs='?', default='', help='查询该日期之后的日志')
    args, unknown_args = parser.parse_known_args()
    author: str = args.author
    after = args.after
    if len(unknown_args) > 0:
        for arg in unknown_args:
            res = re.match("\\d{4}-\\d{2}-\\d{2}", arg)
            if res is not None:
                after = arg
            else:
                author = arg
    if len(author) == 0:
        get_config = config.get_config()
        author = get_config.get("git", "name")
    if len(after) == 0:
        after = utils.this_monday()
    command_line = f"git log --author={author} --after={after} --no-merges --pretty=format:%an--%cs--%s"
    command.exe_command(command_line)


if __name__ == '__main__':
    git_log()
